package wsz.sharding.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import wsz.sharding.entity.Order;

import javax.transaction.Transactional;

/**
 * @author wsz
 * @date 2022/1/19 20:07
 **/
@Repository
public interface OrderRepository extends JpaRepository<Order, Long> {

    /**
     * 分片情况下必须附带分片的关键列
     * @param name
     * @param id
     * @param userId
     */
    @Transactional
    @Modifying
    @Query(value = "update b_order o set o.name= ?1 where o.id = ?2 and o.user_id= ?3", nativeQuery = true)
    void update(String name, Long id, Integer userId);
}
